package com.xindaoapp.happypet.view;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import com.xindaoapp.happypet.activity.MyClubActivity;
import com.xindaoapp.happypet.adapter.HZTAdapter;

public class HZTLayout extends LinearLayout {

    private final Context context;
    private HZTAdapter adapter;

    public HZTLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    public void setAdapter(final HZTAdapter adapter) {
        this.adapter = adapter;
        this.removeAllViews();
        for (int i = 0; i < adapter.getCount(); i++) {
            View view = adapter.getView(i, null, null);
            view.setPadding(10, 0, 10, 0);
            final int position = i;
            view.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (adapter.getList().size() > 0) {
                        Intent intent = new Intent(context, MyClubActivity.class);
                        intent.putExtra("fId", adapter.getList().get(position).fid);
                        intent.putExtra("name", adapter.getList().get(position).name);
                        context.startActivity(intent);
                    }
                }
            });

            this.setOrientation(HORIZONTAL);
            this.addView(view, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT));
        }
    }

}
